import { Application } from "egg";
import { Dingtalk } from "./dingtalk";
import AttService from "./base/AttService";
import DepartmentService from "./base/DepartmentService";
import EventService from "./base/EventService";
import MessageService from "./base/MessageService";
import OAService from "./base/OAService";
import SsoService from "./base/SsoService";
import TodoService from "./base/TodoService";
import TokenService from "./base/TokenService";
import UserService from "./base/UserService";

/** 钉钉api服务类封装 */
export class DingtalkService {
	constructor(public readonly app: Application, public readonly config: Dingtalk.AppConfig) {}

	private _attService?: AttService;
	get attService(): AttService {
		if (!this._attService) {
			this._attService = new AttService(this.app, this.config);
		}
		return this._attService;
	}

	private _departmentService?: DepartmentService;
	get departmentService(): DepartmentService {
		if (!this._departmentService) {
			this._departmentService = new DepartmentService(this.app, this.config);
		}
		return this._departmentService;
	}

	private _eventService?: EventService;
	get eventService(): EventService {
		if (!this._eventService) {
			this._eventService = new EventService(this.app, this.config);
		}
		return this._eventService;
	}

	private _messageService?: MessageService;
	get messageService(): MessageService {
		if (!this._messageService) {
			this._messageService = new MessageService(this.app, this.config);
		}
		return this._messageService;
	}

	private _oaService?: OAService;
	get oaService(): OAService {
		if (!this._oaService) {
			this._oaService = new OAService(this.app, this.config);
		}
		return this._oaService;
	}

	private _ssoService?: SsoService;
	get ssoService(): SsoService {
		if (!this._ssoService) {
			this._ssoService = new SsoService(this.app, this.config);
		}
		return this._ssoService;
	}

	private _todoService?: TodoService;
	get todoService(): TodoService {
		if (!this._todoService) {
			this._todoService = new TodoService(this.app, this.config);
		}
		return this._todoService;
	}

	private _tokenService?: TokenService;
	get tokenService(): TokenService {
		if (!this._tokenService) {
			this._tokenService = new TokenService(this.app, this.config);
		}
		return this._tokenService;
	}

	private _userService?: UserService;
	get userService(): UserService {
		if (!this._userService) {
			this._userService = new UserService(this.app, this.config);
		}
		return this._userService;
	}
}
